import qs from "qs";
import { request } from "@/utils/request";
import { getCurrentOrganizationId, getCurrentUserId } from '@/utils/util.js'
// 当前租户ID
// const getCurrentOrganizationId() = getCurrentOrganizationId()
// 导出
export function exportList(parameter) {
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/project/exportTableData',
    method: 'post',
    data: parameter,
    responseType: 'blob' //服务器返回的数据类型
  })
}
// 我的应用权限
export function myAppPermission(parameter) {
  return request({
    url: `/project/Windchill/servlet/rest/hzero/pmgt/project/hasPidimPermission`,
    method: 'post',
    data: parameter
  })
}
// 获取用户研究院
export function getInstituteData(parameter) {
  return request({
    url: `/project/Windchill/servlet/rest/hzero/pmgt/project/getInstitutes`,
    method: 'post',
    data: parameter
  })
}
// 根据研究院获取临界值
export function getProjectThresholds(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/project-thresholds/institute?institute=${parameter.institute}`,
    method: 'get'
  })
}
// 设置临界值
export function setProjectThresholds(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/project-thresholds`,
    method: 'put',
    data: parameter
  })
}
// 获取表头
export function getProjectAttribute(parameter) {
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectAttribute',
    method: 'post',
    data: parameter,
  })
}
// 获取项目权限--中台入参
export function getProjectPermission(parameter) {
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectPermission',
    method: 'post',
    data: parameter,
  })
}
// 获取清单--中台入参
export function getProjectList(parameter) {
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectList',
    method: 'post',
    data: parameter,
  })
}
// 获取列表数据
export function getProjectCaches(parameter) {
  // let a = qs.stringify(parameter, {
  //   arrayFormat: 'repeat'
  // })
  return request({
    url: `/project/v1/${getCurrentOrganizationId()}/project-caches/oids`,
    method: 'post',
    data: parameter,
  })
}
// 获取关注列表
export function getAttentionsData(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-attentions?userId=${parameter.userId}`,
    method: 'get',
  })
}
// 增加关注列表
export function addAttentionData(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-attentions`,
    method: 'put',
    data: parameter
  })
}
// 获取标签抽屉表格数据
export function getTabTablesData(parameter) {
  let a = qs.stringify(parameter)
  return request({
    url: `/project/v1/${getCurrentOrganizationId()}/project-caches?size=100000&${a}`,
    method: 'get',
  })
}
// 获取标签数据
export function getProjectTags(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-tags?userId=${parameter.userId}`,
    method: 'get',
  })
}
// 添加标签数据
export function addProjectTags(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-tags`,
    method: 'post',
    data: parameter,
  })
}
// 删除标签数据
export function deletProjectTags(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-tags?tagId=${parameter.tagId}&userId=${getCurrentUserId()}`,
    method: 'delete',
  })
}
// 获取新增标签表格数据
export function getNewTagsTable(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-tags/detail`,
    method: 'get',
    params: parameter,
  })
}
// 修改标签
export function editUserTags(parameter) {
  parameter.userId = getCurrentUserId()
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-tags`,
    method: 'put',
    data: parameter
  })
}
// 获取标签筛选数据
export function getUserProjectFilters(parameter) {
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-project-filters?userId=${parameter.userId}&tagName=${parameter.tagName}`,
    method: 'get',
  })
}
// 存储标签筛选数据
export function setUserProjectFilters(parameter) {
  parameter.userId = getCurrentUserId()
  return request({
    url: `/indv/v1/${getCurrentOrganizationId()}/user-project-filters`,
    method: 'put',
    data: parameter
  })
}
// 获取用户所属部门接口
export function getPIProjectsUserGroup(parameter) {
  // parameter.userId = userId
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/project/getPIProjectsUserGroup',
    method: 'post',
    data: parameter,
  })
}
// 获取项目状态
export function getLifeCycleTemplate(parameter) {
  // parameter.userId = userId
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pdm/core/getLifeCycleTemplate',
    method: 'post',
    data: parameter,
  })
}
// 获取项目状态
export function getProjectStates(param) {
  return request({
    url: '/project/Windchill/servlet/rest/hzero/pmgt/report/getProjectStates',
    method: 'post',
    data: param,
  })
}